home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / COMMON / TOOLS / VCM / VCM.MDB / VcmComponentContainer / 02_Cabinet / DATETIME.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-18  |  6.3 KB  |  253 lines

  1. // DateTime.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "RESOURCE.H"
  15. #include "DateTime.h"
  16.  
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CDateTimePage property page
  25.  
  26. IMPLEMENT_DYNCREATE(CDateTimePage, CPropertyPage)
  27.  
  28. CDateTimePage::CDateTimePage() : CPropertyPage(CDateTimePage::IDD)
  29. {
  30.     //{{AFX_DATA_INIT(CDateTimePage)
  31.     m_bAppCanParse = FALSE;
  32.     m_bShowNone = FALSE;
  33.     m_bUpDown = FALSE;
  34.     //}}AFX_DATA_INIT
  35.     m_psp.dwFlags &= ~PSP_HASHELP;  // Lose the Help button
  36. }
  37.  
  38. CDateTimePage::~CDateTimePage()
  39. {
  40. }
  41.  
  42. void CDateTimePage::DoDataExchange(CDataExchange* pDX)
  43. {
  44.     CPropertyPage::DoDataExchange(pDX);
  45.     //{{AFX_DATA_MAP(CDateTimePage)
  46.     DDX_Check(pDX, IDC_CKAPPCANPARSE, m_bAppCanParse);
  47.     DDX_Check(pDX, IDC_CKSHOWNONE, m_bShowNone);
  48.     DDX_Check(pDX, IDC_CKUPDOWN, m_bUpDown);
  49.     //}}AFX_DATA_MAP
  50.     DDX_Control(pDX,IDC_LBNOTIFY,m_lbNotifyList);
  51. }
  52.  
  53.  
  54. BEGIN_MESSAGE_MAP(CDateTimePage, CPropertyPage)
  55.     //{{AFX_MSG_MAP(CDateTimePage)
  56.     ON_BN_CLICKED(IDC_CKUPDOWN, OnCkupdown)
  57.     ON_BN_CLICKED(IDC_CKTIMEFORMAT, OnCktimeformat)
  58.     ON_BN_CLICKED(IDC_CKSHORTDATEFORMAT, OnCkshortdateformat)
  59.     ON_BN_CLICKED(IDC_CKSHOWNONE, OnCkshownone)
  60.     ON_BN_CLICKED(IDC_CKLONGDATEFORMAT, OnCklongdateformat)
  61.     ON_BN_CLICKED(IDC_CKAPPCANPARSE, OnCkappcanparse)
  62.     //}}AFX_MSG_MAP
  63.     ON_NOTIFY(DTN_CLOSEUP,IDC_DATETIME, OnDTNotify)
  64.     ON_NOTIFY(DTN_DATETIMECHANGE,IDC_DATETIME, OnDTNotify)
  65.     ON_NOTIFY(DTN_DROPDOWN ,IDC_DATETIME, OnDTNotify)
  66.     ON_NOTIFY(DTN_FORMAT,IDC_DATETIME, OnDTNotify)
  67.     ON_NOTIFY(DTN_FORMATQUERY,IDC_DATETIME, OnDTNotify)
  68.     ON_NOTIFY(DTN_USERSTRING,IDC_DATETIME, OnDTNotify)
  69.     ON_NOTIFY(DTN_WMKEYDOWN ,IDC_DATETIME, OnDTNotify)
  70. END_MESSAGE_MAP()
  71.  
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CDateTimePage message handlers
  74.  
  75. BOOL CDateTimePage::OnInitDialog()
  76. {
  77.     CPropertyPage::OnInitDialog();
  78.  
  79.     CWnd *pWnd = GetDlgItem(IDC_DTFRAME);
  80.     CRect rc;
  81.     if(!pWnd) return TRUE;
  82.     pWnd->GetWindowRect(rc);
  83.     pWnd->DestroyWindow(); //pWnd was just a placeholder;
  84.     ScreenToClient(rc);
  85.     m_DateTime.Create(WS_CHILD|WS_VISIBLE|DTS_SHORTDATEFORMAT,rc,this,IDC_DATETIME);
  86.     m_nPrevStyle=DTS_SHORTDATEFORMAT;
  87.     SetCheck(IDC_CKSHORTDATEFORMAT);
  88.  
  89.  
  90.     return TRUE;
  91. }
  92.  
  93. void CDateTimePage::OnCkupdown()
  94. {
  95.     UpdateData(TRUE);
  96.  
  97.     if(m_bUpDown)
  98.     {
  99.         CRect rc;
  100.         m_DateTime.GetWindowRect(rc);
  101.         long lStyle = ::GetWindowLong(m_DateTime.m_hWnd,GWL_STYLE);
  102.         lStyle |= DTS_UPDOWN;
  103.         m_DateTime.DestroyWindow();
  104.         ScreenToClient(rc);
  105.         m_DateTime.Create(lStyle,rc,this,IDC_DATETIME);
  106.     }
  107.     else
  108.     {
  109.         CRect rc;
  110.         m_DateTime.GetWindowRect(rc);
  111.         long lStyle = ::GetWindowLong(m_DateTime.m_hWnd,GWL_STYLE);
  112.         lStyle &= ~DTS_UPDOWN;
  113.         m_DateTime.DestroyWindow();
  114.         ScreenToClient(rc);
  115.         m_DateTime.Create(lStyle,rc,this,IDC_DATETIME);
  116.     }
  117.  
  118. }
  119.  
  120.  
  121.  
  122.  
  123.  
  124. void CDateTimePage::OnCkshownone()
  125. {
  126.     UpdateData(TRUE);
  127.     if(m_bShowNone)
  128.     {
  129.         CRect rc;
  130.         m_DateTime.GetWindowRect(rc);
  131.         long lStyle = ::GetWindowLong(m_DateTime.m_hWnd,GWL_STYLE);
  132.         lStyle |= DTS_SHOWNONE;
  133.         m_DateTime.DestroyWindow();
  134.         ScreenToClient(rc);
  135.         m_DateTime.Create(lStyle,rc,this,IDC_DATETIME);
  136.  
  137.     }
  138.     else
  139.     {
  140.         CRect rc;
  141.         m_DateTime.GetWindowRect(rc);
  142.         long lStyle = ::GetWindowLong(m_DateTime.m_hWnd,GWL_STYLE);
  143.         lStyle &= ~DTS_SHOWNONE;
  144.         m_DateTime.DestroyWindow();
  145.         ScreenToClient(rc);
  146.         m_DateTime.Create(lStyle,rc,this,IDC_DATETIME);
  147.     }
  148.  
  149. }
  150.  
  151.  
  152.  
  153. void CDateTimePage::OnCkappcanparse()
  154. {
  155.     UpdateData(TRUE);
  156.     if(m_bAppCanParse)
  157.     {
  158.         CRect rc;
  159.         m_DateTime.GetWindowRect(rc);
  160.         long lStyle = ::GetWindowLong(m_DateTime.m_hWnd,GWL_STYLE);
  161.         lStyle |= DTS_APPCANPARSE;
  162.         m_DateTime.DestroyWindow();
  163.         ScreenToClient(rc);
  164.         m_DateTime.Create(lStyle,rc,this,IDC_DATETIME);
  165.     }
  166.     else
  167.     {
  168.         CRect rc;
  169.         m_DateTime.GetWindowRect(rc);
  170.         long lStyle = ::GetWindowLong(m_DateTime.m_hWnd,GWL_STYLE);
  171.         lStyle &= ~DTS_APPCANPARSE;
  172.         m_DateTime.DestroyWindow();
  173.         ScreenToClient(rc);
  174.         m_DateTime.Create(lStyle,rc,this,IDC_DATETIME);
  175.     }
  176.  
  177. }
  178.  
  179. void CDateTimePage::OnCkshortdateformat()
  180. {
  181.     SetCheck(IDC_CKSHORTDATEFORMAT);
  182.     //remove previous format style
  183.     m_DateTime.ModifyStyle(m_nPrevStyle,0);
  184.     //set this style
  185.     m_DateTime.ModifyStyle(0,DTS_SHORTDATEFORMAT,SWP_NOSIZE);
  186.     m_nPrevStyle=DTS_SHORTDATEFORMAT;
  187. }
  188. void CDateTimePage::OnCklongdateformat()
  189. {
  190.     SetCheck(IDC_CKLONGDATEFORMAT);
  191.  
  192.     //remove previous format style
  193.     m_DateTime.ModifyStyle(m_nPrevStyle,0);
  194.     //set this style
  195.     m_DateTime.ModifyStyle(0,DTS_LONGDATEFORMAT,SWP_NOSIZE);
  196.     m_nPrevStyle=DTS_LONGDATEFORMAT;
  197. }
  198. void CDateTimePage::OnCktimeformat()
  199. {
  200.     SetCheck(IDC_CKTIMEFORMAT);
  201.  
  202.     //remove previous format style
  203.     m_DateTime.ModifyStyle(m_nPrevStyle,0);
  204.     //set this style
  205.     m_DateTime.ModifyStyle(0,DTS_TIMEFORMAT,SWP_NOSIZE);
  206.     m_nPrevStyle=DTS_TIMEFORMAT;
  207. }
  208. void CDateTimePage::SetCheck(UINT idBtn)
  209. {
  210.     static UINT buttons []={IDC_CKTIMEFORMAT,IDC_CKLONGDATEFORMAT,IDC_CKSHORTDATEFORMAT};
  211.     CButton *pBtn=NULL;
  212.     for(int i=0;i<3;i++)
  213.     {
  214.         pBtn = (CButton*)GetDlgItem(buttons[i]);
  215.         if(!pBtn) continue;
  216.  
  217.         if(buttons[i]==idBtn)
  218.             pBtn->SetCheck(1);
  219.         else
  220.             pBtn->SetCheck(0);
  221.     }
  222.  
  223. }
  224.  
  225. void CDateTimePage::OnDTNotify(NMHDR *pHdr, LRESULT * pRes)
  226. {
  227.     switch( pHdr->code)
  228.     {
  229.     case DTN_CLOSEUP:
  230.         m_lbNotifyList.AddString(_T("DTN_CLOSEUP"));
  231.         break;
  232.     case DTN_DATETIMECHANGE:
  233.         m_lbNotifyList.AddString(_T("DTN_DATETIMECHANGE"));
  234.         break;
  235.     case DTN_DROPDOWN:
  236.         m_lbNotifyList.AddString(_T("DTN_DROPDOWN"));
  237.         break;
  238.     case DTN_FORMAT:
  239.         m_lbNotifyList.AddString(_T("DTN_FORMAT"));
  240.         break;
  241.     case DTN_FORMATQUERY:
  242.         m_lbNotifyList.AddString(_T("DTN_FORMATQUERY"));
  243.         break;
  244.     case DTN_USERSTRING:
  245.         m_lbNotifyList.AddString(_T("DTN_USERSTRING"));
  246.         break;
  247.     case DTN_WMKEYDOWN:
  248.         m_lbNotifyList.AddString(_T("DTN_WMKEYDOWN"));
  249.         break;
  250.     }
  251.  
  252. }
  253.